package com.jingan.nursinghome.regulatory.dialog.micrometertable;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jingan.nursinghome.regulatory.R;

import cn.android.support.v7.lib.sin.crown.base.BaseActivity;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.utils.AssetsUtils;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;
import cn.android.support.v7.lib.sin.crown.view.SingleChoose;

/**
 * Created by 彭治铭 on 2017/10/16.
 */

public class ZhengaiDialog extends BaseDialog {
    private ZhengaiDialog(BaseActivity baseActivity) {
        init(baseActivity, R.layout.dialog_zhengai,  false);
        initUI();
        //adapterUI();
    }

    Button btn_cancel;
    SingleChoose single_xianchan,single_jihua;
    public void initUI() {
        btn_cancel = (Button) findViewById(R.id.btn_cancel);
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        single_xianchan= (SingleChoose) findViewById(R.id.single_xianchan);
        single_jihua= (SingleChoose) findViewById(R.id.single_jihua);
        Bitmap general= AssetsUtils.getInstance().getBitmapFromAssets("图标/圆形默认.png",0,true);
        general= ProportionUtils.getInstance().adapterBitmap(general);
        Bitmap selected= AssetsUtils.getInstance().getBitmapFromAssets("图标/圆形选择.png",0,true);
        selected= ProportionUtils.getInstance().adapterBitmap(selected);
        single_xianchan.setTextColor(Color.parseColor("#818181"));
        single_xianchan.setMession("现场整改");
        single_xianchan.setBitmap(general,selected);
        single_xianchan.setCancel(true);

        single_jihua.setTextColor(Color.parseColor("#818181"));
        single_jihua.setMession("计划整改");
        single_jihua.setBitmap(general,selected);
        single_jihua.setCancel(true);

        window.setWindowAnimations(cn.android.support.v7.lib.sin.crown.R.style.crown_window_alpha);
        //single_xianchan.setTextSize(UtilProportion.getInstance(baseActivity).adapterInt(38));
    }

    public void adapterUI() {
        ProportionUtils.getInstance().adapterScreen(baseActivity, findViewById(R.id.dialog_zhengai_constraintLayout));
        ProportionUtils.getInstance().adapterView(findViewById(R.id.dialog_zhengai_constraintLayout_content));
        ProportionUtils.getInstance().adapterTextView((TextView) findViewById(R.id.txt_title));
        ProportionUtils.getInstance().adapterButton(btn_cancel);
        ProportionUtils.getInstance().adapterView(findViewById(R.id.view_line));
        ProportionUtils.getInstance().adapterView(single_xianchan);
        ProportionUtils.getInstance().adapterView(single_jihua);
    }

    private static ZhengaiDialog zhengaiDialog;

    //0什么都没有，1现场整改，2计划整改
    static int model=0;
    static BaseListenner<Integer> mBaseListenner;
    public static ZhengaiDialog getInstance(BaseActivity baseActivity,int mode,BaseListenner<Integer> baseListenner) {
        model=mode;
        mBaseListenner=baseListenner;
        if (isfinish(baseActivity,zhengaiDialog)) {
            zhengaiDialog = new ZhengaiDialog(baseActivity);
        }
        return zhengaiDialog;
    }

    @Override
    protected void listener() {
        single_xianchan.setOnStateChangeListener(null);
        single_jihua.setOnStateChangeListener(null);
        if(model==0){
            single_xianchan.setState(false);
            single_jihua.setState(false);
        }
        if(model==1){
            single_xianchan.setState(true);
            single_jihua.setState(false);
        }
        if(model==2){
            single_xianchan.setState(false);
            single_jihua.setState(true);
        }

        single_xianchan.setOnStateChangeListener(new BaseListenner<SingleChoose>() {
            @Override
            public void onResult(SingleChoose result) {
                if(result.isState()){
                    model=1;
                }else{
                    model=0;
                }
                if(mBaseListenner!=null){
                    mBaseListenner.onResult(model);
                    dismiss();
                }
            }
        });

        single_jihua.setOnStateChangeListener(new BaseListenner<SingleChoose>() {
            @Override
            public void onResult(SingleChoose result) {
                if(result.isState()){
                    model=2;
                }else{
                    model=0;
                }
                if(mBaseListenner!=null){
                    mBaseListenner.onResult(model);
                    dismiss();
                }
            }
        });

    }

    @Override
    protected void recycleView() {

    }
}
